package com.greystripe.sdk;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.Size;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import java.util.List;
import java.util.Timer;

public final class GSFullscreenActivity extends Activity
  implements Camera.PictureCallback
{
  private ay a;
  private FrameLayout b;
  private GSFullscreenAd c;
  private at d;
  private int e = -1;
  private Camera f;
  private Camera.Parameters g;
  private CameraPreview h;
  private boolean i;
  private Timer j;

  private void b(int paramInt)
  {
    if (this.f == null)
    {
      bd.b("camera was null", new Object[0]);
      return;
    }
    this.g = this.f.getParameters();
    if (Integer.parseInt(Build.VERSION.SDK) >= 8)
      this.f.setDisplayOrientation(90);
    while (true)
    {
      this.f.setParameters(this.g);
      return;
      if (paramInt == 1)
      {
        bd.b("cam rotating to portrait", new Object[0]);
        this.g.set("orientation", "portrait");
      }
      if (paramInt == 2)
      {
        bd.b("cam rotating to landscape", new Object[0]);
        this.g.set("orientation", "landscape");
      }
    }
  }

  private void c()
  {
    if (Build.VERSION.SDK_INT >= 11)
      this.c.j().setLayerType(0, null);
    this.b.addView(this.a);
    this.d.setRootLayout(this.b);
  }

  private Camera d()
  {
    Camera localCamera = null;
    if (Integer.parseInt(Build.VERSION.SDK) >= 9)
    {
      Camera.CameraInfo localCameraInfo = new Camera.CameraInfo();
      int k = Camera.getNumberOfCameras();
      int m = 0;
      while (true)
        if (m < k)
        {
          Camera.getCameraInfo(m, localCameraInfo);
          if (localCameraInfo.facing == 1);
          try
          {
            localCamera = Camera.open(m);
            this.i = true;
            m++;
          }
          catch (RuntimeException localRuntimeException)
          {
            while (true)
            {
              bd.b("Front camera failed to open", new Object[0]);
              localRuntimeException.printStackTrace();
            }
          }
        }
      if (localCamera == null)
        localCamera = e();
      return localCamera;
    }
    return e();
  }

  private Camera e()
  {
    this.i = false;
    try
    {
      Camera localCamera = Camera.open();
      return localCamera;
    }
    catch (RuntimeException localRuntimeException)
    {
      bd.b("Back camera failed to open", new Object[0]);
      localRuntimeException.printStackTrace();
    }
    return null;
  }

  private Camera f()
  {
    try
    {
      Camera localCamera = d();
      return localCamera;
    }
    catch (Exception localException)
    {
      bd.b("Camera does not exist.", new Object[0]);
      localException.printStackTrace();
    }
    return null;
  }

  private void g()
  {
    if (this.c == null);
    int k;
    do
    {
      return;
      k = this.c.m();
    }
    while (k == this.e);
    bd.b("cam orientation changed!", new Object[0]);
    this.c.j().b("EventHandler.broadcastEvent('orientationchange', " + this.c.m() + ");");
    this.e = k;
  }

  final int a()
  {
    return getResources().getConfiguration().orientation;
  }

  final void a(int paramInt)
  {
    bd.b("fullscreenactivity#setOrientation(" + paramInt + ")", new Object[0]);
    setRequestedOrientation(paramInt);
    g();
  }

  protected final void b()
  {
    bd.b("FullscreenActivity#lockOrientation()", new Object[0]);
    switch (a())
    {
    default:
      return;
    case 2:
      a(0);
      return;
    case 1:
      a(1);
      return;
    case 3:
      a(1);
      return;
    case 0:
    }
    a(1);
  }

  public final void onBackPressed()
  {
    bd.b("onBackPressed", new Object[0]);
    if (this.j != null)
    {
      this.j.cancel();
      this.j.purge();
    }
    this.d.a();
    this.c.k();
  }

  public final void onConfigurationChanged(Configuration paramConfiguration)
  {
    super.onConfigurationChanged(paramConfiguration);
    g();
  }

  protected final void onCreate(Bundle paramBundle)
  {
    setTheme(16973841);
    super.onCreate(paramBundle);
    if (GSFullscreenAd.c == null)
    {
      finish();
      return;
    }
    this.c = GSFullscreenAd.c;
    this.d = this.c.d;
    this.c.a(this);
    this.d.setActivity(this);
    this.a = new ay(this, this.c);
    this.b = new FrameLayout(this);
    g();
    RelativeLayout localRelativeLayout;
    int m;
    long l;
    List localList;
    int n;
    int i1;
    Object localObject1;
    int i2;
    label232: Object localObject2;
    int i6;
    int i7;
    if (this.c.b)
    {
      this.i = false;
      this.f = f();
      if (this.f != null)
        if (this.i)
        {
          b(-1);
          this.h = new CameraPreview(this, this.f);
          this.g = this.f.getParameters();
          localRelativeLayout = new RelativeLayout(this);
          DisplayMetrics localDisplayMetrics = getResources().getDisplayMetrics();
          int k = localDisplayMetrics.widthPixels;
          m = localDisplayMetrics.heightPixels;
          if (k < m)
            m = k;
          l = ()(0.1D * Runtime.getRuntime().maxMemory());
          localList = this.g.getSupportedPictureSizes();
          n = 0;
          i1 = 0;
          localObject1 = null;
          i2 = 0;
          if (i2 >= localList.size())
            break label345;
          localObject2 = (Camera.Size)localList.get(i2);
          i6 = ((Camera.Size)localObject2).width;
          i7 = ((Camera.Size)localObject2).height;
          if (i6 >= i7)
            break label686;
        }
    }
    while (true)
    {
      int i10;
      int i9;
      if ((i7 * i6 <= l) && (i7 > n) && (i6 > i1))
      {
        i10 = ((Camera.Size)localObject2).width;
        i9 = ((Camera.Size)localObject2).height;
      }
      while (true)
      {
        i2++;
        n = i10;
        i1 = i9;
        localObject1 = localObject2;
        break label232;
        b(1);
        break;
        label345: if (localObject1 == null)
          localList.get(0);
        bd.b("picture size: w:" + n + ", h: " + i1, new Object[0]);
        this.g.setPictureSize(n, i1);
        this.f.setParameters(this.g);
        if (i1 > m)
          n = (int)(n / i1 * m);
        while (true)
        {
          int i3 = (int)TypedValue.applyDimension(1, n, getResources().getDisplayMetrics());
          int i4 = (int)TypedValue.applyDimension(1, m, getResources().getDisplayMetrics());
          if (i3 > i4);
          while (true)
          {
            bd.b("dipw: " + i4 + ", diph: " + i3, new Object[0]);
            if (Build.VERSION.SDK_INT >= 11)
              this.c.j().setLayerType(1, null);
            RelativeLayout.LayoutParams localLayoutParams1 = new RelativeLayout.LayoutParams(i4, i3);
            localLayoutParams1.addRule(13);
            localRelativeLayout.addView(this.h, localLayoutParams1);
            RelativeLayout.LayoutParams localLayoutParams2 = new RelativeLayout.LayoutParams(-1, -1);
            localRelativeLayout.addView(this.a, localLayoutParams2);
            this.b.addView(localRelativeLayout);
            this.j = new Timer();
            this.j.scheduleAtFixedRate(new az(this), 500L, 2000L);
            while (true)
            {
              setContentView(this.b);
              return;
              c();
              continue;
              c();
            }
            int i5 = i4;
            i4 = i3;
            i3 = i5;
          }
          m = i1;
        }
        localObject2 = localObject1;
        i9 = i1;
        i10 = n;
      }
      label686: int i8 = i7;
      i7 = i6;
      i6 = i8;
    }
  }

  public final void onPictureTaken(byte[] paramArrayOfByte, Camera paramCamera)
  {
    try
    {
      paramCamera.startPreview();
      ActivityManager localActivityManager = (ActivityManager)getSystemService("activity");
      bd.b("pic memory: " + localActivityManager.getMemoryClass(), new Object[0]);
      bd.b("pic runtime memory: " + Runtime.getRuntime().maxMemory(), new Object[0]);
      bd.b("pic byte memory: " + paramArrayOfByte.length, new Object[0]);
      Bitmap localBitmap1 = BitmapFactory.decodeByteArray(paramArrayOfByte, 0, paramArrayOfByte.length);
      bd.b("allocated decodedPicture", new Object[0]);
      localMatrix = new Matrix();
      if (this.i)
      {
        localMatrix.preScale(-1.0F, 1.0F);
        if (localBitmap1.getWidth() > localBitmap1.getHeight())
        {
          bd.b("rotating 270 degrees", new Object[0]);
          localMatrix.preRotate(270.0F);
        }
        Bitmap localBitmap2 = Bitmap.createBitmap(localBitmap1, 0, 0, localBitmap1.getWidth(), localBitmap1.getHeight(), localMatrix, false);
        bd.b("allocated picture", new Object[0]);
        bd.b("decoded picture w " + localBitmap2.getWidth() + " h " + localBitmap2.getHeight(), new Object[0]);
        bm.a(new ba(this, localBitmap2));
        return;
      }
    }
    catch (Exception localException)
    {
      while (true)
      {
        Matrix localMatrix;
        localException.printStackTrace();
        onBackPressed();
        continue;
        localMatrix.preRotate(90.0F);
      }
    }
  }

  protected final void onStop()
  {
    super.onStop();
    if (!this.c.l())
    {
      bd.b("ad didn't have interaction", new Object[0]);
      this.c.k();
    }
    bd.b("closeActivity()", new Object[0]);
    if (this.j != null)
    {
      this.j.cancel();
      this.j.purge();
    }
    this.a.a();
    this.d.clearReferences();
    this.c.n();
    this.c.d();
    GSFullscreenAd.c = null;
    finish();
  }

  public final void takeScreenshot()
  {
    if (this.f != null)
      this.f.takePicture(null, null, this);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.greystripe.sdk.GSFullscreenActivity
 * JD-Core Version:    0.6.2
 */